#pragma once
#include <d3dx9.h>
#include <string>
#include <vector>

using std::string;
using std::vector;

#include "../basiclib/Common.h"
#include "../basiclib/collision.h"
#include "../basiclib/texture.h"
#include "../renderer/Sprite.h"
#include "../game/state.h"


namespace TGO
{
	struct Step
	{
									Step( int cnt, string anim ):mCnt( cnt ), mAnim( anim ) { }
		string						mAnim;
		int							mCnt;
	};

	class Manner
	{
	public:
									Manner():mTracer( 0 ) { }
									Manner( vector< Step > steps ):mTracer( 0 ), mStepList( steps ) { }
		Step						NextStep( int role_state, UINT& cnt );

		void						SetStepList( vector< Step > stepList );
	private:
		Step						NextStepNormal( UINT& cnt );
		int							NextTracer();

		vector< Step >				mStepList;
		int							mTracer;
	};

	class Role
	{
	public:
									Role() {}
									Role( D3DXVECTOR2 pos, UINT width, UINT height, float speed = 2.0f );
		virtual						~Role() { }

		virtual void				Update( float dt ) { }

		void						WalkR() { mPos += mSpeed * x_normal; }
		void						WalkL() { mPos -= mSpeed * x_normal; }
		void						WalkF() { mPos -= mSpeed * y_normal; }
		void						WalkB() { mPos += mSpeed * y_normal; }

		void						SetPos( D3DXVECTOR2 pos ) { mPos = pos; }
		void						SetWidth( UINT width ) { mWidth = width; }
		void						SetHeight( UINT height ) { mHeight = height; }
		void						SetRoleState( int roleState ) { mRoleState = roleState; }
		void						SetSpriteID( Tgo2DEntity* id ) { mSpriteID = id; }
		void						SetTexID( string id ) { mTexID = id; }
		void						SetAnimID( int animID ) { mAnimID = animID; }
		void						SetBBoxID( int bboxID ) { mBBoxID = bboxID; }
		void						SetCurrentAnim( string currAnim ) { mCurrAnim = currAnim; }
		void						SetSpeed( float speed ) { mSpeed = speed; }

		D3DXVECTOR2					GetPos() { return mPos; }
		UINT						GetWidth() { return mWidth; }
		UINT						GetHeight() { return mHeight; }
		int							GetRoleState() { return mRoleState; }
		Tgo2DEntity*				GetSpriteID() { return mSpriteID; }
		string						GetTexID() { return mTexID; }
		int							GetAnimID() { return mAnimID; }
		int							GetBBoxID() { return mBBoxID; }
		string						GetCurrAnim() { return mCurrAnim; }
		float						GetSpeed() { return mSpeed; }

	protected:
		TimeCounter					mTimeCounter;
		D3DXVECTOR2					mPos;
		UINT						mWidth;
		UINT						mHeight;
		float						mSpeed;
		int							mRoleState;
		string						mCurrAnim;

		Tgo2DEntity*				mSpriteID;
		string						mTexID;
		int							mAnimID;
		int							mBBoxID;
	};

	class AI:public Role
	{
	public:
									AI():Role(), mCounter( 0 ) { }
									AI( D3DXVECTOR2 pos, UINT width, UINT height, float speed = 2.0f )
										:Role( pos, width, height, speed ), mCounter( 0 ){ }
		virtual						~AI() { }

		virtual	void				Update( float dt ) { }

		void						SetAIManner( Manner m ) { mManner = m; }
	protected:
		Manner						mManner;
		UINT						mCounter;
	};

	class Monster:public AI
	{
	public:

									~Monster() { }
		virtual void				Update( float dt );
	private:
		UINT						mHP;
		UINT						mDefend;
	};

	class NPC:public AI
	{
	public:
									NPC():AI() { }
									NPC( D3DXVECTOR2 pos, UINT width, UINT height, float speed = 2.0f ):AI( pos, width, height, speed )
																												{ }
									~NPC() { }

		virtual void				Update( float dt );
	};

	class FriendRole:public Role
	{
	public:
									FriendRole():Role() { }
									FriendRole( D3DXVECTOR2 pos, UINT width, UINT height, float speed = 2.0f ):Role( pos, width, height, speed ) { }
									~FriendRole() { }

		virtual void				Update( float dt );

		UINT						GetHP() { return mHP; }
		UINT						GetDefend() { return mDefend; }
	private:
		UINT						mHP;
		UINT						mDefend;						

	};

}
